#include "L6452.h"
/*****************************
*函数名称：L6452_Init
*函数功能：初始化6452的IO
*输入功能：none
*输出功能：none
******************************/
void L6452_Init(void)
{
	//定义变量
	GPIO_InitTypeDef GPIO_InitStructure;
	//RCC设置
	switch((uint32_t)L6452_S0_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_S1_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_S2_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_S3_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_CHSEL_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_ENCH_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_SDA_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}	
	switch((uint32_t)L6452_SCK_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_LATCHCLEAR_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_LATCHDATA_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}	
	switch((uint32_t)L6452_NCEN_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_LONGPULSE_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_SHORTPULSE_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)L6452_RESET_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}	
	switch((uint32_t)EN_244_PORT)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}	
	//IO设置
	//CHSEL	Channel A 与 ChannelB选择   当chsel为低电平的时候选择A 高电平选择B
	GPIO_InitStructure.GPIO_Pin		=	L6452_CHSEL_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_CHSEL_PORT, &GPIO_InitStructure);	
	//S0  选择 HSA 或者HSB
	GPIO_InitStructure.GPIO_Pin		=	L6452_S0_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_S0_PORT, &GPIO_InitStructure);	
	//S1  选择 HSA 或者HSB
	GPIO_InitStructure.GPIO_Pin		=	L6452_S1_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_S1_PORT, &GPIO_InitStructure);	
	//S2  选择 HSA 或者HSB
	GPIO_InitStructure.GPIO_Pin		=	L6452_S2_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_S2_PORT, &GPIO_InitStructure);	
	//S3  选择 HSA 或者HSB
	GPIO_InitStructure.GPIO_Pin		=	L6452_S3_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_S3_PORT, &GPIO_InitStructure);	
	//NCEN 可以控制使用墨盒检测功能还是打印功能 如果高电平则使用墨盒检测功能  低电平则使用的是喷墨检测功能
	GPIO_InitStructure.GPIO_Pin		=	L6452_NCEN_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_NCEN_PORT, &GPIO_InitStructure);
	GPIO_ResetBits(L6452_NCEN_PORT,L6452_NCEN_PIN);							//默认输出低电平	
	//LATCHCLEAR 高电平会复位锁存器 就是让锁存器的引脚全部输出低电平
	GPIO_InitStructure.GPIO_Pin		=	L6452_LATCHCLEAR_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_LATCHCLEAR_PORT, &GPIO_InitStructure);
	//NCOUT	墨盒检测功能中使用的 如果NCOUT是高电平则说明喷头是好的， 否则为坏的
	GPIO_InitStructure.GPIO_Pin		=	L6452_NCOUT_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_IN_FLOATING ;				//浮空输入
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_NCOUT_PORT, &GPIO_InitStructure);	
	//ENCH 低电平使能被选中的channel
	GPIO_InitStructure.GPIO_Pin		=	L6452_ENCH_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_ENCH_PORT, &GPIO_InitStructure);
	GPIO_SetBits(L6452_ENCH_PORT,L6452_ENCH_PIN);							//默认输出高电平
	//RESET 如果为低电平则会失能所有功能 并且清所有的寄存器
	GPIO_InitStructure.GPIO_Pin		=	L6452_RESET_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_RESET_PORT, &GPIO_InitStructure);
	GPIO_SetBits(L6452_RESET_PORT,L6452_RESET_PIN);							//默认输出高电平	
	//shortpulse 低电平 使能 STAGES 也就是power开始输出 并且复位锁存器
	GPIO_InitStructure.GPIO_Pin		=	L6452_SHORTPULSE_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;   				//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_SHORTPULSE_PORT, &GPIO_InitStructure);
	GPIO_SetBits(L6452_SHORTPULSE_PORT,L6452_SHORTPULSE_PIN);				//默认输出高电平	
	//longpulse 低电平 使能 STAGES 也就是power开始输出 并且复位锁存器
	GPIO_InitStructure.GPIO_Pin		=	L6452_LONGPULSE_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;   				//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_LONGPULSE_PORT, &GPIO_InitStructure);
	GPIO_SetBits(L6452_LONGPULSE_PORT,L6452_LONGPULSE_PIN);					//默认输出高电平	
	//SCK 时钟线 串并转换
	GPIO_InitStructure.GPIO_Pin		=	L6452_SCK_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_SCK_PORT, &GPIO_InitStructure);
	GPIO_SetBits(L6452_SCK_PORT,L6452_SCK_PIN);								//默认为高电平	
	//SDI 数据线 串并转换
	GPIO_InitStructure.GPIO_Pin		=	L6452_SDA_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ; 					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_SDA_PORT, &GPIO_InitStructure);
	GPIO_SetBits(L6452_SDA_PORT,L6452_SDA_PIN); 							//默认输出高电平 	
	//latchdata 上升沿 触发锁存器锁存数据
	GPIO_InitStructure.GPIO_Pin		=	L6452_LATCHDATA_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ; 					//推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(L6452_LATCHDATA_PORT, &GPIO_InitStructure);	
	
    //EN244  
	GPIO_InitStructure.GPIO_Pin		=	EN_244_PIN;
	GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_Out_PP ;                  //推挽输出
	GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;
	GPIO_Init(EN_244_PORT, &GPIO_InitStructure);
	GPIO_SetBits(EN_244_PORT,EN_244_PIN); 					                //默认输出高电平 
    
	//开机上电清除所有寄存器 并且失能所有功能	       
	L6452_RESET_L();			
	delay_ms(100);
	L6452_RESET_H(); 
	//开机就选择墨盒喷墨的功能
    L6452_NCEN_L();
	//禁止power输出
	L6452_LONGPULSE_H();
    L6452_SHORTPULSE_H();
    // 打开244
    EN_244_ON();        
}


//单片机向L6452传power数据
/***************************
*函数名称：L6452_SendPowerTo6452
*函数功能：单片机将power数据串行的传给L6452
*输入参数：Pn就是被选中的P的值
*备注：通过串并转换将power映射到墨盒
*	   数据设置时间最小为35ns
*      数据保持时间最小为35ns
***************************/
static void L6452_SendPowerTo6452(uint16_t Pn)
{                        
	//拉低时钟开始数据传输
	L6452_SCK_L(); 
	//串行的一位一位的发出bit数
	for(uint8_t i = 0;i < 16;i++)
	{  
		//下降沿更新数据线
		L6452_SCK_L();
		//先高位后低位
		if(Pn & 0x8000)
			L6452_SDA_H();
		else
			L6452_SDA_L();
		//一个上升沿发送一个bit		
		L6452_SCK_H();
		//发送下一位
		Pn	<<=	1;		   
	}	 
} 

//S0 —— S3 与HSA 和 HSB的映射表
static uint16_t HS_Table[16]={0x0000,0x0001,0x0003,0x0002,0x0006,0x0007,0x0005,0x0004,0x000C,0x000D,0x000F,0x000E,0x000A,0x0008,0x0009,0x000B};
//uint16_t HS_Table[16]={0x0000,0x1000,0x3000,0x2000,0x6000,0x7000,0x5000,0x4000,0xC000,0xD000,0xF000,0xE000,0xA000,0x8000,0x9000,0xB000};

//输出Channel
/**********************
*函数名称：L6452_ChannelOutput
*函数功能：通道输出
*输入参数：channel ：通道选择 A 或者B  numb：第几个通道
*输出参数：none
************************/
void L6452_ChannelOutput(uint8_t channel,uint8_t numb)
{
	uint8_t hs	=	0;
	//使能244
	EN_244_ON();
	//Channel失能
	L6452_ENCH_H(); 
	//delay_us(1);
	//通道选择
	if(channel	==	CHANNEL_A)
	{
		//选中channel A
		L6452_CHSEL_L();
	}
	else if(channel	==	CHANNEL_B)
	{
		//选中channel B
		L6452_CHSEL_H();
	}
	
	//将表中的值给s0-s3赋值
	//取出表中的值
	hs	=	HS_Table[numb];
	//S0 输出
	if(hs & (1 << 0))
		GPIO_SetBits(L6452_S0_PORT,L6452_S0_PIN);
	else
		GPIO_ResetBits(L6452_S0_PORT,L6452_S0_PIN);
	//S1 输出 
	if(hs & (1 << 1))
		GPIO_SetBits(L6452_S1_PORT,L6452_S1_PIN);
	else
		GPIO_ResetBits(L6452_S1_PORT,L6452_S1_PIN);	
	//S2 输出
	if(hs & (1 << 2))
		GPIO_SetBits(L6452_S2_PORT,L6452_S2_PIN);
	else
		GPIO_ResetBits(L6452_S2_PORT,L6452_S2_PIN);	
	//S3 输出
	if(hs & (1 << 3))
		GPIO_SetBits(L6452_S3_PORT,L6452_S3_PIN);
	else
		GPIO_ResetBits(L6452_S3_PORT,L6452_S3_PIN);	
	
	//使能channel
	L6452_ENCH_L();
}

//控制power输出
/****************************************
*函数名称：L6452_PowerOutput
*函数功能：控制power输出
*输入参数：要输出的P
*输出参数：none
***************************************/
void L6452_PowerOutput(uint16_t Pn)
{
	//保持锁存器的值不变 也就是Power的值不变
	L6452_LATCHCLEAR_L(); 
	//longpulse置为高电平 power失能 不输出
	L6452_LONGPULSE_H();
	//向L6452发power值
	L6452_SendPowerTo6452(Pn);
	//先释放锁存器
	L6452_LATCHDATA_L();
	//锁存数据
	L6452_LATCHDATA_H();
	//关闭总中断
	MAIN_CloseIRQ(); 
	//Power输出 
    //Power开始输出电平 （并且复位锁存器）
    L6452_LONGPULSE_L();
    //输出的时间
    delay_nus(INK_JET_TIME);
    //关闭power的输出 
    L6452_LONGPULSE_H();
	//开启总中断
    MAIN_OpenIRQ();   
	//失能channel
	L6452_ENCH_H();  
	//等待锁存下一组数据
	L6452_LATCHDATA_L();  	
}


//长加热次数变量
static uint16_t LongHeatCnt     =   10000;
//短加热次数变量
static uint16_t ShortHeatCnt    =   300;
/******************************
*函数名：void L6452_HeatInkDriver(uint8_t channel,uint8_t n)
*功能：加热A列喷头
*输入：CHANNEL_A  / CHANNEL_B  n   =   1 ~ 13
*输出：none
*****************************************/
static void L6452_HeatInkDriver(uint8_t channel,uint8_t n)
{
    L6452_ChannelOutput(channel,n);//选中A
    //Power开始输出电平 （并且复位锁存器）
    L6452_LONGPULSE_L();  
    delay_nus(HEAT_INK_HOLD_TIME);
    //关闭power的输出 
    L6452_LONGPULSE_H();
}

/*************************************
*函数名称：void L6452_HeatInk(uint32_t cycle)
*函数功能：加热墨盒
*输入参数：cycle：加热次数
*输出参数：none
**************************************/
void L6452_HeatInk(uint32_t cycle)
{
	//保持锁存器的值不变 也就是Power的值不变
	L6452_LATCHCLEAR_L(); 
	//longpulse置为高电平 power失能 不输出
	L6452_LONGPULSE_H();
	//向L6452发power值
	L6452_SendPowerTo6452(0xffff);
	//先释放锁存器
	L6452_LATCHDATA_L();
	//锁存数据
	L6452_LATCHDATA_H();
	//关闭总中断
	MAIN_CloseIRQ(); 
    for(int i=0;i < cycle;i++)
    {
        L6452_HeatInkDriver(CHANNEL_A,1);
        L6452_HeatInkDriver(CHANNEL_A,2);
        L6452_HeatInkDriver(CHANNEL_A,3);
        L6452_HeatInkDriver(CHANNEL_A,4);
        L6452_HeatInkDriver(CHANNEL_A,5);
        L6452_HeatInkDriver(CHANNEL_A,6);
        L6452_HeatInkDriver(CHANNEL_A,7);
        L6452_HeatInkDriver(CHANNEL_A,8);
        L6452_HeatInkDriver(CHANNEL_A,9);
        L6452_HeatInkDriver(CHANNEL_A,10); 
        L6452_HeatInkDriver(CHANNEL_A,11);
        L6452_HeatInkDriver(CHANNEL_A,12);
        L6452_HeatInkDriver(CHANNEL_A,13);        
        L6452_HeatInkDriver(CHANNEL_B,1);
        L6452_HeatInkDriver(CHANNEL_B,2);
        L6452_HeatInkDriver(CHANNEL_B,3);
        L6452_HeatInkDriver(CHANNEL_B,4);
        L6452_HeatInkDriver(CHANNEL_B,5);
        L6452_HeatInkDriver(CHANNEL_B,6);
        L6452_HeatInkDriver(CHANNEL_B,7);
        L6452_HeatInkDriver(CHANNEL_B,8);
        L6452_HeatInkDriver(CHANNEL_B,9);
    }
	//开启总中断
    MAIN_OpenIRQ();   
	//失能channel
	L6452_ENCH_H();  
	//等待锁存下一组数据
	L6452_LATCHDATA_L(); 
}

/*************************************
*函数名称：L6452_ModifHeatProperty
*函数功能：修改加热次数的参数
*输入参数：长加热次数，短加热次数
*输出参数：none
**************************************/
void L6452_ModifHeatProperty(uint16_t longcnt,uint16_t shortcnt) 
{
    LongHeatCnt     =   longcnt;
    ShortHeatCnt    =   shortcnt;
}

/*************************************
*函数名称：L6452_GetLongHeatCnt
*函数功能：输出长加热次数
*输入参数：none
*输出参数：none
**************************************/
uint16_t L6452_GetLongHeatCnt(void)
{
    return  LongHeatCnt;
}

/*************************************
*函数名称：L6452_GetShortHeatCnt
*函数功能：输出短加热次数
*输入参数：none
*输出参数：none
**************************************/
uint16_t L6452_GetShortHeatCnt(void)
{
    return  ShortHeatCnt;
}